package org.devastra.arcinspect.core.data;

import org.devastra.arcinspect.core.data.cache.EntityInfoCache;


public class PackageInfo extends AbstractEntityInfo {

	public PackageInfo(String name) {
		super(name, EntityType.PACKAGE, false);
	}
	
	public PackageInfo(EntityInfo _entity) {
		super(_entity, EntityType.PACKAGE, false);
	}
	
	public static synchronized PackageInfo getPackage(String _pkgName) {
		
		PackageInfo pkgInfo = null;
		try {
			EntityInfo info = EntityInfoCache.getEntityInfo(_pkgName);
			if(info == null) {
				pkgInfo = new PackageInfo(_pkgName);
			} else if (EntityType.UNKNOWN.equals(info.getType())) {
				pkgInfo = new PackageInfo(info);
			} else if (EntityType.PACKAGE.equals(info.getType())) {
				pkgInfo = (PackageInfo) info;
			} else {
				//should not happen
				System.out.println("Error : should not happen");
			}
		} catch (ClassCastException e) {
			System.out.println("Error getting package :"+_pkgName);
			e.printStackTrace();
			//System.exit(0);
		}
		
		//debug
		//System.out.println("getPackage: "+_pkgName+" : "+info);
		return pkgInfo;
	}
	
}
